Merged [13770]: Enabled saving ICQ aliases set in Adium to the server. Fixes #466
[adiumx.git] / Gaim Service / adiumGaimWebcam.m
blob1e5ecd6fe5831d8c0906f51a76a9d5c46ee2cbfb
1 /* 
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6  * General Public License as published by the Free Software Foundation; either version 2 of the License,
7  * or (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
11  * Public License for more details.
12  * 
13  * You should have received a copy of the GNU General Public License along with this program; if not,
14  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15  */
17 #import "adiumGaimWebcam.h"
19 #pragma mark Webcam
20 static void adiumGaimWebcamNew(GaimWebcam *gwc)
22         GaimDebug(@"adiumGaimWebcamNew");
23         //      GaimGtkWebcam *c;
24         //      char *tmp;
25         //      
26         //      c = g_new0(GaimGtkWebcam, 1);
27         //      
28         //      gwc->ui_data = c;
29         //      c->gwc = gwc;
30         //      
31         //      c->button = gaim_pixbuf_button_from_stock(_("Close"), GTK_STOCK_CLOSE, GAIM_BUTTON_HORIZONTAL);
32         //      c->vbox = gtk_vbox_new(FALSE, 0);
33         //      gtk_box_pack_end_defaults(GTK_BOX(c->vbox), GTK_WIDGET(c->button));
34         //      
35         //      c->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
36         //      tmp = g_strdup_printf(_("%s's Webcam"), gwc->name);
37         //      gtk_window_set_title(GTK_WINDOW(c->window), tmp);
38         //      g_free(tmp);
39         //      
40         //      gtk_container_add(GTK_CONTAINER(c->window), c->vbox);
41         //      
42         //      g_signal_connect(G_OBJECT(c->button), "clicked",
43         //                                       G_CALLBACK(gaim_gtk_webcam_close_clicked), c);
44         //      
45         //      g_signal_connect(G_OBJECT(c->window), "destroy",
46         //                                       G_CALLBACK(gaim_gtk_webcam_destroy), c);
47         //      
48         //      c->image = gtk_image_new_from_stock(GAIM_STOCK_LOGO, gtk_icon_size_from_name(GAIM_ICON_SIZE_LOGO));
49         //      gtk_box_pack_start_defaults(GTK_BOX(c->vbox), c->image);
50         //      gtk_widget_show(GTK_WIDGET(c->image));
51         //      
52         //      gtk_widget_show(GTK_WIDGET(c->button));
53         //      gtk_widget_show(GTK_WIDGET(c->vbox));
54         //      gtk_widget_show(GTK_WIDGET(c->window));
57 static NSMutableData    *frameData = nil;
59 static void adiumGaimWebcamUpdate(GaimWebcam *gwc,
60                                                                   const unsigned char *image, unsigned int size,
61                                                                   unsigned int timestamp, unsigned int id)
63         GaimDebug(@"adiumGaimWebcamUpdate (Frame %i , %i bytes)", id, size);
64         
65         if(!frameData){
66                 frameData = [[NSMutableData alloc] init];               
67         }
68         
69         [frameData appendBytes:image length:size];
70         
71         //      GaimGtkWebcam *cam;
72         //      WCFrame *f;
73         //      GError *e = NULL;
74         //      
75         //      gaim_debug_misc("gtkwebcam", "Got %d bytes of frame %d.\n", size, id);
76         //      
77         //      cam = gwc->ui_data;
78         //      if (!cam)
79         //              return;
80         //      
81         //      f = wcframe_find_by_no(cam->frames, id);
82         //      if (!f) {
83         //              f = wcframe_new(cam, id);
84         //              cam->frames = g_list_append(cam->frames, f);
85         //      }
86         //      
87         //      if (!gdk_pixbuf_loader_write(f->loader, image, size, &e)) {
88         //              gaim_debug(GAIM_DEBUG_MISC, "gtkwebcam", "gdk_pixbuf_loader_write failed:%s\n", e->message);
89         //              g_error_free(e);
90         //      }
93 static void adiumGaimWebcamFrameFinished(GaimWebcam *wc, unsigned int id)
95         GaimDebug(@"adiumGaimWebcamFrameFinished");
96         
97         NSBitmapImageRep *rep;
98         rep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:(unsigned char **)[frameData bytes]
99                                                                                                   pixelsWide:320
100                                                                                                   pixelsHigh:240
101                                                                                            bitsPerSample:8
102                                                                                          samplesPerPixel:3
103                                                                                                         hasAlpha:NO
104                                                                                                         isPlanar:NO
105                                                                                           colorSpaceName:NSCalibratedRGBColorSpace
106                                                                                                  bytesPerRow:0
107                                                                                                 bitsPerPixel:0]; 
108         
109         GaimDebug(@"rep = %@",rep);
110         
111         //      [[AIObject sharedAdiumInstance] performSelectorOnMainThread:@selector(showImage:) withObject:rep waitUntilDone:NO];
112         
113         //      NSImage *tmp = [[NSImage alloc] init];
114         //      [tmp addRepresentation:rep];
115         
116         
117         
118         
119         
120         
121         //      [rep release];
122         [frameData release]; frameData = nil;
123         
124         
125         
126         
127         
128         //      GaimDebug(@"Bitmap?: %@",[NSImage initWithData:frameData]);
129         
130         //      GaimGtkWebcam *cam;
131         //      WCFrame *f;
132         //      
133         //      cam = wc->ui_data;
134         //      if (!cam)
135         //              return;
136         //      f = wcframe_find_by_no(cam->frames, id);
137         //      if (!f)
138         //              return;
139         //      
140         //      gdk_pixbuf_loader_close(f->loader, NULL);
141         //      f->loader = NULL;
144 static void adiumGaimWebcamClose(GaimWebcam *gwc)
146         GaimDebug(@"adiumGaimWebcamClose");
147         //      GaimGtkWebcam *cam;
148         //      
149         //      cam = gwc->ui_data;
150         //      if (!cam)
151         //              return;
152         //      
153         //      cam->gwc = NULL;
154         //      gwc->ui_data = NULL;
157 static void adiumGaimWebcamGotInvite(GaimConnection *gc, const gchar *who)
159         GaimDebug(@"adiumGaimWebcamGotInvite");
160         
161         gaim_webcam_invite_accept(gc, who);
162         
163         
164         //      gchar *str = g_strdup_printf(_("%s has invited you (%s) to view their Webcam."), who,
165         //                                                               gaim_connection_get_display_name(gc));
166         //      struct _ggwc_gcaw *g = g_new0(struct _ggwc_gcaw, 1);
167         //      
168         //      g->gc = gc;
169         //      g->who = g_strdup(who);
170         //      
171         //      gaim_request_action(gc, _("Webcam Invite"), str, _("Will you accept this invitation?"), 0,
172         //                                              g, 2, _("Accept"), G_CALLBACK(_invite_accept), _("Decline"),
173         //                                              G_CALLBACK(_invite_decline));
174         //      
175         //      g_free(str);
178 static struct gaim_webcam_ui_ops adiumGaimWebcamOps =
180         adiumGaimWebcamNew,
181         adiumGaimWebcamUpdate,
182         adiumGaimWebcamFrameFinished,
183         adiumGaimWebcamClose,
184         adiumGaimWebcamGotInvite
187 struct gaim_webcam_ui_ops *adium_gaim_webcam_get_ui_ops(void)
189         return &adiumGaimWebcamOps;
192 void initGaimWebcamSupport(void)
194         //Init the plugin
195         gaim_init_j2k_plugin();
196         
197         //Set the UI Ops
198         gaim_webcam_set_ui_ops(adium_gaim_webcam_get_ui_ops());